CROSS_COMPILE ?=arm-linux-gnueabihf-
CC  = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)g++
AR  = $(CROSS_COMPILE)ar

ALKAID_PATH ?= ./../..
ENABLE_HDMI ?= 1

COM_FLAGS = -march=armv7-a -mtune=cortex-a7 -mfpu=neon -O2 -Wall -fPIC -mthumb-interwork -marm -g -funwind-tables -ffunction-sections -rdynamic
C_FLAGS   = $(COM_FLAGS) -std=c11
CPP_FLAGS = $(COM_FLAGS) -std=c++11

INCLUDES := -I. -I../player/include -I../ffmpeg/include -I$(ALKAID_PATH)/project/release/include
LIB_PATH := -L. -L../player/lib -L../ffmpeg/lib -L../openssl -L$(ALKAID_PATH)/project/release/nvr/i2m/common/glibc/8.2.1/mi_libs/dynamic

TARGET_NAME := ssplayer

CPP_SRCS  = $(wildcard ./*.cpp)
C_SRCS    = $(wildcard ./*.c)

CPP_OBJS  = $(patsubst %.cpp, %.cpp.o, $(CPP_SRCS))
C_OBJS    = $(patsubst %.c, %.c.o, $(C_SRCS))

LIB_NAME  = -lssplayer
LIB_NAME += -lavformat -lavcodec -lavutil -lswscale -lswresample
LIB_NAME += -lssl -lcrypto

ifeq ($(ENABLE_HDMI),1)
LIB_NAME  += -lmi_hdmi
else
LIB_NAME  += -lmi_panel
endif

LIB_NAME += -lmi_vdec -lmi_divp -lmi_disp -lmi_ao -lmi_gfx -lmi_sys -lmi_common

.PHONY: all prepare clean

all: prepare $(TARGET_NAME) finish

prepare:
	@echo
	@echo ">>>>========================================================"
	@echo "TARGET_NAME = $(TARGET_NAME)"
	@echo

clean:
	@rm -rf $(CPP_OBJS)
	@rm -rf $(C_OBJS)
	@rm -rf $(TARGET_NAME)

finish:
	@echo "make done"
	@echo "<<<<========================================================"
	@echo

$(TARGET_NAME): $(CPP_OBJS) $(CPP_SRCS) $(C_OBJS) $(C_SRCS)
	@echo "generate $@"
	@$(CPP) -o $@ $(C_OBJS) $(CPP_OBJS) $(LIB_PATH) $(LIB_NAME) -ldl -lm -lpthread

%.c.o : %.c
	@echo "compile $@"
	@$(CC) -DENABLE_HDMI=$(ENABLE_HDMI) $(C_FLAGS) $(INCLUDES) -c $< -o $@

%.cpp.o : %.cpp
	@echo "compile $@"
	@$(CPP) -DENABLE_HDMI=$(ENABLE_HDMI) $(CPP_FLAGS) $(INCLUDES) -c $< -o $@

